import 'package:flutter/material.dart';
import 'package:flutter_module/beans/data_layer_item_bean.dart';
import 'package:flutter_module/viewModels/layer_edit_viewmodel.dart';
import 'package:provider/provider.dart';

///项目选择列表页面
class LayerItemTypeListFragment extends StatelessWidget {
  const LayerItemTypeListFragment({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    ///路由工具
    final NavigatorState _navi = Navigator.of(context);
    late final LayerEditViewModel _read =
        Provider.of<LayerEditViewModel>(context, listen: false);
    return Scaffold(
      backgroundColor: Colors.grey,
      appBar: AppBar(
        ///返回按钮
        leading: BackButton(
          onPressed: () {
            _navi.pop();
          },
        ),
      ),
      body: ListView.builder(
        itemCount: 2,
        itemBuilder: (BuildContext context, int index) {
          switch (index) {
            case 0:
              return Card(
                child: ListTile(
                  title: Text(LayerItemConstant.getTypeName(
                      DataLayerItemType.dataLayerItemTypeInput)),
                  leading: LayerItemConstant.getTypeIcon(
                      DataLayerItemType.dataLayerItemTypeInput),
                  trailing: const Icon(Icons.arrow_forward_ios),
                  subtitle: const Text("可输入任意字符"),
                  onTap: () {
                    // ///选择项目，返回上一页
                    _read.setLayerItemType(
                        DataLayerItemType.dataLayerItemTypeInput);
                    _navi.pop();
                  },
                ),
              );
            case 1:
              return Card(
                child: ListTile(
                  title: Text(LayerItemConstant.getTypeName(
                      DataLayerItemType.dataLayerItemTypeSingleSelection)),
                  leading: LayerItemConstant.getTypeIcon(
                      DataLayerItemType.dataLayerItemTypeSingleSelection),
                  trailing: const Icon(Icons.arrow_forward_ios),
                  subtitle: const Text("可输入任意字符"),
                  onTap: () {
                    // ///选择项目，返回上一页
                    _read.setLayerItemType(
                        DataLayerItemType.dataLayerItemTypeSingleSelection);
                    _navi.pop();
                  },
                ),
              );
            default:
              return Container();
          }
        },
      ),
    );
  }
}

class LayerItemConstant {
  static String getTypeName(DataLayerItemType type) {
    switch (type) {
      case DataLayerItemType.dataLayerItemTypeInput:
        return "文本输入框";
      case DataLayerItemType.dataLayerItemTypeInputArray:
        break;
      case DataLayerItemType.dataLayerItemTypeText:
        break;
      case DataLayerItemType.dataLayerItemTypeSingleSelection:
        return "单选框";
      case DataLayerItemType.dataLayerItemTypeMultipleSelection:
        break;
    }
    return "未定义";
  }

  static Icon getTypeIcon(DataLayerItemType type) {
    switch (type) {
      case DataLayerItemType.dataLayerItemTypeInput:
        return const Icon(Icons.text_format_outlined);
      case DataLayerItemType.dataLayerItemTypeInputArray:
        break;
      case DataLayerItemType.dataLayerItemTypeText:
        break;
      case DataLayerItemType.dataLayerItemTypeSingleSelection:
        return const Icon(Icons.adjust_outlined);
      case DataLayerItemType.dataLayerItemTypeMultipleSelection:
        break;
    }
    return const Icon(Icons.warning_amber_outlined);
  }
}
